package com.hongdee.base.sendMsg.controller;

import com.hongdee.base.sendMsg.service.ISendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/base/sendMsg")
public class SendMsgController {

    @Autowired
    private ISendMsgService iSendMsgService;

    /**
     * 一个内容发送多个人
     * @param uid
     * @param token
     * @param content
     * @param extno
     * @param mobiles
     * @return
     * @throws Exception
     */
    @RequestMapping("/send")
    @ResponseBody
    public Map sendMsg(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "content", defaultValue = "无内容") String content,
                        @RequestParam(name = "extno", defaultValue = "") String extno,
                        @RequestBody List<String> mobiles
                      ) throws Exception {

        String resultString =  iSendMsgService.sendGet(content,mobiles,extno);
        System.out.println(resultString);
        Map map = new HashMap<>();
        map.put("msg",resultString);
        return map;
    }

    /**
     * 多个内容发送多个人
     * @param uid
     * @param token
     * @param extno
     * @param list
     * @return
     * @throws Exception
     */
    @RequestMapping("/sendMsg")
    @ResponseBody
    public Map send(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "extno", defaultValue = "") String extno,
                    @RequestBody List<Map<String,Object>> list
    ) throws Exception {

        String resultString =  iSendMsgService.sendPost(list,extno);
        System.out.println(resultString);
        Map map = new HashMap<>();
        map.put("msg",resultString);
        return map;
    }

}
